package net.m2technologies.open_arm;

import net.m2technologies.open_arm.tranreport.ArmTranReportFactoryImpl;
import net.m2technologies.open_arm.transaction.ArmTransactionFactoryImpl;
import net.m2technologies.open_arm.transport.TransportMediatorBroker;
import net.m2technologies.open_arm.transport.TransportMediatorBrokerImpl;
import org.opengroup.arm40.tranreport.ArmTranReportFactory;
import org.opengroup.arm40.transaction.ArmTransactionFactory;

/**
 * Copyright 2005 Mark Masterson<br> <br> Licensed under the Apache License, Version 2.0 (the "License");<br> you may
 * not use this file except in compliance with the License.<br> You may obtain a copy of the License at<br> <br>
 * http://www.apache.org/licenses/LICENSE-2.0<br> <br> Unless required by applicable law or agreed to in writing,
 * software<br> distributed under the License is distributed on an "AS IS" BASIS,<br> WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied.<br> See the License for the specific language governing permissions and<br>
 * limitations under the License.<br>
 * <p/>
 * <p>Description: </p>
 *
 * @author Mark Masterson
 * @version 0.010
 */
public class OpenArmAgent {

    private static final void preLoadGuidFactories() {
        try {
            Class.forName("net.m2technologies.open_arm.utilities.guid.RandomGUID");
        } catch (ClassNotFoundException e) {
            // can't happen, and we can't do anything about it anyway...
        }
    }

    static {
        preLoadGuidFactories();
    }

    private final ArmTransactionFactory transactionFactory;
    private final ArmTranReportFactory transactionReportFactory;

    public OpenArmAgent(final String configFileName) {
        this(new TransportMediatorBrokerImpl(configFileName));
    }

    public OpenArmAgent(final OpenArmConfiguration configuration) {
        this(new TransportMediatorBrokerImpl(configuration.getMediatorConfigurations()));
    }

    private OpenArmAgent(final TransportMediatorBroker broker) {
        this.transactionFactory = new ArmTransactionFactoryImpl(broker);
        this.transactionReportFactory = new ArmTranReportFactoryImpl(broker);
    }

    public ArmTransactionFactory getTransactionFactory() {
        return transactionFactory;
    }

    public ArmTranReportFactory getTransactionReportFactory() {
        return transactionReportFactory;
    }

}
